#!/usr/bin/perl -w
##############################################################################
#
# test_Linux_Obj.pl
# =======================
#
# Author: Steven Liang <stliang@gmail.com>
#
# Purpose:
#   A child class of Linux.pm.  This script demonstrate how to inherit the Linux.pm
#   class.  It also shows a way to extend the "new" constructor.
#
# Steps:
#
#   1.) Instantiate a Linux object and call it Localhost
#   2.) Start a telnet session to target host
#   3.) Log the entire telnet session to a file
#   4.) Login to the target host
#   5.) Execute Linux's "su" command
#   6.) Exit
#
# Expected result:
#
#   The user be in super user mode 
#
##############################################################################

package main;
$VERSION = 1.01;

# If the PERLLIB environment variable is not set like
# "export PERLLIB=<lib directory>" then uncomment the
# following two lines:
# use FindBin qw($Bin); 
# use lib "$Bin/./lib";
use Node;
use Linux;

my $Localhost = undef;

if ((defined $ENV{'PAT_ROOT'}) && (defined $ENV{'PAT_LOG'})) {
  # Instantiate a Linux object and call it Localhost
  $Localhost = Linux->new("localhost", "tester", "password", 23);

  # Start a telnet session to target host
  $Localhost->openTelnet();

  # Log the entire telnet session to a file
  $Localhost->log($ENV{'PAT_LOG'} . "test_Linux_Obj.log");

  # Login to the target host
  $Localhost->login(qr/login/, qr/Password:/, qr/autons tester/);

  # Execute Linux's "su" command
  $Localhost->su("password", qr/Password:/, qr/#/);

  # Kill the Iperf process
  $Localhost->kill("iperf");

  # Find the port name of a given IP address
  my $portName = $Localhost->getPortName("118.1.1.1");
  print "\nDEBUG: found $portName\n";

  # Set MTU size of a network port
  $Localhost->setMTU("118.1.1.1", "512");

  # Release Localhost's resource
  $Localhost->DESTROY();
}

undef $Localhost;
